<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<script src="../js/jquery-3.5.1.min.js"></script>
		<script src="../js/jsencrypt.min.js"></script>
		<script>

		var encryptor = new JSEncrypt();
        encryptor.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCBJzjaOJCvy3hciAasAT9H47d/ql4U4b45Uvj5cUpqoxMIy1znrQKFagmbXNdXzpjwElpq6Ve7+JpqQsjTnzXI4ahn8Z2nfQ6TfoiOCy/aCH2dnRhyl9XcetZNfxfCN7dTibj8Ik6b2Th3iEiiBngHU3NxAk6Se11mk7rsCQnR+QIDAQAB");

	$.fn.serializeObject = function()   
	{   
	   var o = {};   
	   var a = this.serializeArray();   
	   $.each(a, function() {   
		   if (o[this.name]) {   
			   if (!o[this.name].push) {   
				   o[this.name] = [o[this.name]];   
			   }   
			   o[this.name].push(this.value || '');   
		   } else {   
			   if(this.value){
				   o[this.name] = encryptor.encrypt(this.value);
			   }else{
				   o[this.name] = '';
			   }
		   }   
	   });   
	   return o;   
	};  　　

		
    </script>
	</head>
	<body>
		<form id="from2" method="post">
			账号：<input type="text" name="username" value="xjr" />
			<br />
			昵称：<input type="text" name="name" value="小贱人" />
			<br />
			密码：<input type="text" name="password" value="123456" />
			<br />
			验证码：<input type="text" name="code" value="" />
			<br />
			<img id="vc" src="http://localhost:8080/vc" width="150px" height="50px">
			<br>
			<input onclick="userLogin()" type="button" value="注册" />
		</form>
		<textarea hidden="hidden" style="width: 80%;height: 300px;background-color: #FFE4C4; " id="text">
&#10;
		</textarea>
		<script>
			function userLogin() {
				var jsonData = $("#from2").serializeObject();
				$.ajax({
					url: 'http://localhost:8080/user/register',
					type: 'POST',
					dataType: 'json',
					contentType: 'application/json;charset=UTF-8',
					data: JSON.stringify(jsonData),
					xhrFields: {
						withCredentials: true //保证session一致
					},
					success: function(resultJson) {
						if(resultJson.code==200){
							alert("注册成功");
						}else if("开发角色"=="开发角色"){
							var data="";
							data+="状态:" + resultJson.code;
							data+="&#10;==========&#10;";
							data+="消息:" + resultJson.msg;
							data+="&#10;==========&#10;";
							data+=JSON.stringify(resultJson.data);
							$("#text").html(data);
							$("#text").show();
						}else{
							alert("注册失败");
						}
					}
				});
			}
			
			window.onload = function() {
				$("#vc").on("click", function() {
					$("#vc").attr("src", "http://localhost:8080/vc?" + new Date().getTime());
				});
			}
		</script>
	</body>
</html>
